<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

require_once(dirname(__FILE__) . '/../lib/BasesfGuardAuthActions.class.php');

/**
 *
 * @package    symfony
 * @subpackage plugin
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
 * @version    SVN: $Id: actions.class.php 7634 2008-02-27 18:01:40Z fabien $
 */
class sfGuardAuthActions extends BasesfGuardAuthActions
{

  public function executeSignin($request)
  {
    ##SOLO SACAR ESTA LINEA PARA EMPEZAR A USAR EL WSDL##
//    parent::executeSignin($request);
    ###LOGIN POR WEB SERVISE##
    if ($request->isMethod('get'))
    {
      parent::executeSignin($request);
    }
    else
    {
      $ip = $_SERVER['REMOTE_ADDR'];
      $singin_request = $request->getParameter('signin');
      $url_security_client_wsdl = sfConfig::get("app_security_client_wsdl");
      $client = new SoapClient($url_security_client_wsdl);
      $user_wsdl = $client->login($singin_request['username'], $singin_request['password'], $ip);
//      var_dump($user_wsdl);die();
      if ($user_wsdl->code == 1)
      {
        $this->getUser()->setFlash('notice', $user_wsdl->message, false);
        $this->getUser()->setAttribute('wsdl', $user_wsdl);

        parent::executeSignin($request);
      }
      else
      {
        $this->getUser()->setFlash('notice', $user_wsdl->message);
        $signoutUrl = sfConfig::get('app_sf_guard_plugin_success_signout_url', $request->getReferer());
        $this->redirect('' != $signoutUrl ? $signoutUrl : '@homepage');
      }
    }

  }

  public function executeSignout($request)
  {
    $url_security_client_wsdl = sfConfig::get("app_security_client_wsdl");
    $client = new SoapClient($url_security_client_wsdl);
    $client->logout($this->getUser()->getUsername());
    parent::executeSignout($request);

  }

}
